# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: xguo

import json
import logging
import os

from coin2.support.product_info.spot_kraken_v1 import convert_coin1_constants

pi_file = 'data/coin2/product_info/Spot.Kraken.v1.json'
with open(pi_file) as f:
  static_constants = convert_coin1_constants(json.load(f)['product_infos'])

dynamic_constants = {}
if int(os.getenv('USE_DYNAMIC_SYMBOL', 0)):
  try:
    from coin2.support.product_info.spot_kraken_v1 import gen_coin1_constants
    dynamic_constants = gen_coin1_constants()
  except Exception as e:
    logging.error('Failed to use kraken dynamic symbols! %s', e)

quote_currency_list = list(set(
    static_constants.get('quote_currency_list', []) +
    dynamic_constants.get('quote_currency_list', [])))
currency_list = list(set(
    ['BSV', 'FEE'] +
    static_constants.get('currency_list', []) +
    dynamic_constants.get('currency_list', [])))
clean_symbol_list = list(set(
    static_constants.get('clean_symbol_list', []) +
    dynamic_constants.get('clean_symbol_list', [])))

# Actively traded sybomls according to their volume.
active_symbol_list = [
    "XXBTZUSD",
    "XXBTZEUR",
    "XETHZUSD",
    "XETHZEUR",
    "BCHUSD",
    'XXRPZEUR',
    "XETHXXBT",
    "EOSEUR",
    "BCHEUR",
    "EOSUSD",
    "XXRPZUSD",
    "BCHXBT",
    'XETCZUSD',
    'XLTCZEUR',
    'XETCZEUR',
    'LTCUSD',
    'EOSXBT',
]

native_quote_currency_list = [
    "XETH",
    "XXBT",
    "ZCAD",
    "ZEUR",
    "ZGBP",
    "ZJPY",
    "ZUSD",
]

# Store as a list of (name, altname) pairs.
native_currency_list = [
    ("BCH", "BCH"),
    ("BSV", "BSV"),
    ("DASH", "DASH"),
    ("EOS", "EOS"),
    ("GNO", "GNO"),
    ("OMG", "OMG"),
    ("XTZ", "XTZ"),
    ("KFEE", "FEE"),
    ("USDT", "USDT"),
    ("XDAO", "DAO"),
    ("XETC", "ETC"),
    ("XETH", "ETH"),
    ("XICN", "ICN"),
    ("XLTC", "LTC"),
    ("XMLN", "MLN"),
    ("XNMC", "NMC"),
    ("XREP", "REP"),
    ("XXBT", "XBT"),
    ("XXDG", "XDG"),
    ("XXLM", "XLM"),
    ("XXMR", "XMR"),
    ("XXRP", "XRP"),
    ("XXVN", "XVN"),
    ("XZEC", "ZEC"),
    ("ZCAD", "CAD"),
    ("ZEUR", "EUR"),
    ("ZGBP", "GBP"),
    ("ZJPY", "JPY"),
    ("ZKRW", "KRW"),
    ("ZUSD", "USD"),
    ("LINK", "LINK"),
]

# Minimum amounts are not queryable, get them here
# https://support.kraken.com/hc/en-us/articles/205893708-What-is-the-minimum-order-size-
#
# Augur (REP): 0.3
# Bitcoin (XBT): 0.002
# Bitcoin Cash (BCH): 0.002
# Dash (DASH): 0.03
# Dogecoin (DOGE): 3000
# EOS (EOS): 3
# Ethereum (ETH): 0.02
# Ethereum Classic (ETC): 0.3
# Gnosis (GNO): 0.03
# Iconomi (ICN): 2
# Litecoin (LTC): 0.1
# Melon (MLN): 0.1
# Monero (XMR): 0.1
# Ripple (XRP): 30
# Stellar Lumens (XLM): 30
# Zcash (ZEC): 0.03
# Tether (USDT): 5

# key: normalized currency symbol
min_order_qty = {
    'REP': 0.3,
    'BTC': 0.002,
    'BCHABC': 0.000002,
    'BCHSV': 0.000002,
    'ADA': 1,
    'DASH': 0.03,
    'DOGE': 3000,
    'EOS': 3,
    'ETH': 0.02,
    'ETC': 0.3,
    'GNO': 0.03,
    'ICN': 2,
    'LTC': 0.1,
    'MLN': 0.1,
    'XMR': 0.1,
    'XRP': 30,
    'XLM': 30,
    'XTZ': 1,
    'ZEC': 0.03,
    'USDT': 5,
}
